<template>
	<view class="content">
		<view class="cbody">
			<home v-if="tabIndex==0"></home>
			<user v-if="tabIndex==1"></user>
		</view>
		<view>
			<view class="navbar">
				<view class="tab-item" :class="{'active':tabIndex==0}" @click="tabIndex=0">
					<image :src="baseUrl + '/wximage/index_footer1.png'" v-if="tabIndex == 0"></image>
					<image :src="baseUrl + '/wximage/index_footer11.png'" v-else></image>
					<view :class="{'xuanzhong':tabIndex==0}">首页</view>
				</view>
				<view class="tab-item" :class="{'active':tabIndex==1}" @click="tabIndex=1">
					<image :src="baseUrl + '/wximage/index_footer2.png'" v-if="tabIndex == 1"></image>
					<image :src="baseUrl + '/wximage/index_footer22.png'" v-else></image>
					<view :class="{'xuanzhong':tabIndex==1}">我的</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import home from '@/subpackageA/home/index.vue';
	import user from '@/subpackageA/user/index.vue';

	export default {
		async created() {
			await this.$onLaunched;
		},
		onLoad(options) {
			if (options.tabIndex) {
				this.tabIndex = options.tabIndex
			}
			
			// 用户信息
			this.request({
				url: '/agent/users',
				data: {
					id: uni.getStorageSync('agent_id'),
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					if(res.data.data.delete_status == 2){
						uni.showModal({
							title: '提示',
							content: '您的账号已被封禁,请联系管理员',
							success: function (res) {
								if (res.confirm) {
									uni.setStorageSync('agent_id');
									uni.setStorageSync('role_id');
									uni.showToast({
										title: '退出成功',
										icon: 'none'
									})
									setTimeout(function(){
										uni.reLaunch({
											url: '/pages/index/index'
										})
									},2000)
								} else if (res.cancel) {
									uni.setStorageSync('agent_id');
									uni.setStorageSync('role_id');
									uni.showToast({
										title: '退出成功',
										icon: 'none'
									})
									setTimeout(function(){
										uni.reLaunch({
											url: '/pages/index/index'
										})
									},2000)
								}
							}
						})
					}
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
		},
		data() {
			return {
				tabIndex: 0,
				baseUrl: getApp().globalData.baseUrl,
			}
		},
		methods: {
			
		},
		watch: {

		},
		components: {
			home,
			user
		}
	}
</script>

<style lang="scss" scoped>
	.navbar {
		background-color: #fff;
		position: fixed;
		z-index: 99;
		bottom: 0;
		left: 0;
		display: flex;
		width: 100%;
		height: 100rpx;
		align-items: center;
		justify-content: space-around;
		border-top: 1rpx solid #cacacf;

		.tab-item {
			width: 50%;
			text-align: center;
			
			image{
				width: 56rpx;
				height: 56rpx;
				margin-top: 10rpx;
			}

			view {
				font-size: $uni-font-size-base;
				text-align: center;
				color: $uni-text-color-grey;
				margin-top: -10rpx;
				margin-bottom: 10rpx;
			}
		}

		.active {
			view {
				color: $uni-text-color;
			}
		}
	}
</style>